/**
 * Created by douxc on 2015/2/11
 * 模仿android里面的Toast效果，主要是用于在不打断程序正常执行的情况下显示提示数据
 * @param config
 * @return
 */
define(function (require, exports, module) {
  'use strict';
  var Toast = function (msg) {
    this.message = msg;//显示内容
    this.context = $('body');
    //this.time = (config.time == null) ? 3000 : config.time;//持续时间
    //this.context = (config.context == null) ? $('body') : config.context;//上下文
    this.init();
  };
  var msgEntity;
  Toast.prototype = {
    //初始化显示的位置内容等
    init: function () {
      $("#toastMessage").remove();
      //设置消息体
      var msgDIV = [];
      msgDIV.push('<div class="mh-tips mh-tips-bottom" id="toastMessage">');
      msgDIV.push('<div class="mh-tips-content">');
      //msgDIV.push('<span class="am-icon-anchor"></span>' + "&nbsp;&nbsp;" + this.message + '</div>');
      msgDIV.push(this.message + '</div>');
      msgDIV.push('</div>');
      msgEntity = $(msgDIV.join('')).appendTo(this.context);
      msgEntity.hide();
    },
    //显示动画,显示1.8秒后渐变消失
    show: function () {
      //msgEntity.animate({top: "16px"});
      msgEntity.fadeIn(200);
      setTimeout(function () {
        msgEntity.fadeOut(200);
      }, 2000);
      //msgEntity.show();
      //setTimeout(function () {
      //  msgEntity.animate({top: "-50px"});
      //  msgEntity.hide();
      //}, 2000);
    }
  };
  module.exports = {
    show: function (data) {
      new Toast(data).show();
    }
  };
});
